#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-09-14 11:54 上午
# @Author  : yangdy
# @File    : 2020-09-14.94.二叉树的中序遍历
# @Software: PyCharmCE
from tools.my_methods import *


# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def inorderTraversal(self, root: TreeNode) -> List[int]:
        ans = []

        # def dfs(rt):
        #     if not rt:
        #         return
        #     dfs(rt.left)
        #     ans.append(rt.val)
        #     dfs(rt.right)
        #
        # dfs(root)
        stack = []
        cur = root
        while stack or cur:
            if cur:
                stack.append(cur)
                cur = cur.left
            else:
                cur = stack.pop()
                ans.append(cur.val)
                cur = cur.right

        return ans


questions = [
    ([1, None, 2, 3],)
]

# print(questions[0][0])
# rt = mk_tree(questions[0][0], TreeNode)
# display(rt)

work(questions, lambda q: Solution().inorderTraversal(mk_tree(q[0], TreeNode)))

